package com.levtech.moviemanager.contact;

import com.levtech.moviemanager.MovieManagerApp;
import com.levtech.moviemanager.R;
import com.levtech.moviemanager.db.DataStore;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;

public class AddContactActivity extends Activity
{
        
        private DataStore store;

        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_add_contact);
                this.store = ((MovieManagerApp)this.getApplication()).getStore();
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu)
        {
                // Inflate the menu; this adds items to the action bar if it is present.
                getMenuInflater().inflate(R.menu.add_contact, menu);
                return true;
        }
    	
    	@Override
    	public boolean onOptionsItemSelected(MenuItem selection)
    	{
    		switch(selection.getItemId())
    		{
    			case R.id.edit_contact:	//startActivity(new Intent(this, EditContactActivity.class));
    									return true;
    			
    			case R.id.view_contact:	startActivity(new Intent(this, ViewContactActivity.class));
    									return true;
    			
    			default: return super.onOptionsItemSelected(selection);
    		}
    	}
        
        public void addContact(View view)
        {
                Contact c = new Contact(((EditText)findViewById(R.id.firstField)).getText().toString(),
                                ((EditText)findViewById(R.id.lastField)).getText().toString(),
                                ((EditText)findViewById(R.id.phoneField)).getText().toString());
                
                this.store.insertContact(c);
                
                //return to previous screen
                finish();
        }
    	
    	public void cancelAdd(View view)
    	{
    		finish();
    	}

}

